package com.hxl.tech.gateway.auth.dto;


import lombok.Data;

import java.util.List;


@Data
public class Page<T> {

    private List<T> result;

    private PageInfo pageInfo;

    public static <T> Page<T> of(PageRequest pageRequest, Long totalCount, List<T> t) {
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageNumber(pageRequest.getPageNumber());
        pageInfo.setPageSize(pageRequest.getPageSize());

        pageInfo.setTotalCount(totalCount);
        long page = totalCount % pageInfo.getPageSize() == 0 ? totalCount / pageInfo.getPageSize() : totalCount / pageInfo.getPageSize() + 1;
        pageInfo.setTotalPage((int) page);
        Page<T> result = new Page<>();
        result.setPageInfo(pageInfo);
        result.setResult(t);
        return result;
    }
}
